package com.sgame.smobigame;

import java.util.ArrayList;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class HappeningAdapter extends ArrayAdapter<itemHappening> {

	private Context context;
	private ArrayList<itemHappening> array;

	public HappeningAdapter(Context context, int textViewResourceId,
			ArrayList<itemHappening> objects) {
		super(context, textViewResourceId, objects);
		this.context = context;
		this.array = objects;
	}
	public View getView(int position, View convertView, ViewGroup parent) {
		View happenView = convertView;
		if(happenView==null){
			happenView = new itemLayoutHappening(context);
		}
		
		final itemHappening happen = array.get(position); //lay 1 doi tuong cua mang student
		if(happen!=null){
			// thuc viec gan cac thuoc tinh cua student cho tung thanh phan cau tao len item cua listview lay tung thanh phan cau tao len item cua listview
			ImageView imgAvatar = ((itemLayoutHappening)happenView).ivAvatar;
			TextView tvDate = ((itemLayoutHappening)happenView).tvDate;
			TextView tvContent = ((itemLayoutHappening)happenView).tvContent;
			ImageView imgSetting =((itemLayoutHappening)happenView).ivSetting;
			
			//+ xet gia tri cho tung thanh phan
			imgAvatar.setImageBitmap(happen.getIvAvatar());
			tvDate.setText(happen.getDate());
			tvContent.setText(happen.getContent());
			imgSetting.setImageBitmap(happen.getIvSetting());
			
			// lang nghe khi co su thay doi chon cua ivSetting
			
		}
		return happenView;
		
	} 

}
